import Guide from '@/components/Guide';
import { ArrayHas, getEvenCount, getHistory, getHistoryStr, getOddAndEven, trim } from '@/utils/format';
import { PageContainer } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { Button, Form, Input } from 'antd';
import { useEffect, useState } from 'react';
import {
  sampleSize, //获得随机数
  uniq, //去重
  take, //从0开始获得指定数组
  takeRight,
  slice//裁剪数组
} from "lodash"

import HistoryList from '@/components/Guide/HistoryList';
import IndexLocation from '@/components/Guide/IndexLocation';
import { getFilterResult } from '../Home/getFilterResult';

const Table: React.FC = () => {
  
  const [buyResult, setBuyResult] = useState<any>([]);
  const [data, setData] = useState({
    historyListTop20:[],//最近的20期
    result:[],//所有可能的结果
    nearByList: [],//去掉上一期上下浮动20万条数据
    continue4:[],//4连号
    continue3:[],//3连号
    oneMore456:[],//1区大于4 5 6个数
    twoMore456:[],//2区大于4 5 6个数
    threeMore456:[],//3区大于4 5 6个数
    evenCount6: [],//偶数6
    evenCount5: [],//偶数5
    oddCount6: [],//奇数6
    oddCount5: [],//奇数5
    drop1112And2223: [],//去掉对称数（比如01&02和32&33）
    dropTopOddAndEevn: [],//去掉最近20期的奇偶
    filterResult:[],//过滤后的号码
  });//所有结果
  
  let {
    allRedBallList,
    allRedBallStrList,
    historyList,
    historyResultStrList,
    historyOddEvenList,
    historyOddEvetTongj
  } = useModel("ballModel")

  let {
    sortListObj//奇偶组合距离上次出现的期数距离作为key，出现多少次作为值
  } = historyOddEvetTongj;

  return (
    <PageContainer ghost>
      <p>验证开奖号码是否在筛选范围内，在最新一期号码更新前有效</p>
      <table cellPadding={0}>
        <thead>
          <tr>
              <td>号码</td>
              <td>奇偶情况</td>
              <td>奇偶距上一次出现期数</td>
              <td></td>
              <td>出现索引区间</td>
              <td></td>
          </tr>
        </thead>
        <tbody>
          <HistoryList />
          {
            buyResult.map((item, index)=>{
              let itemStr = item.join("");
              let currentOddEven = getOddAndEven(item);
              let currentJiange = historyOddEvenList.indexOf(currentOddEven);//historyOddEvenList是最近一期在第一个，所以从左往右找到索引号，就是当前号码距离最新的间隔
              let locationIndex = allRedBallStrList.indexOf(itemStr);
              return <tr key={index} className="chooseTr">
                <td>{item}</td>
                <td>{currentOddEven}</td>
                <td>
                  {currentJiange}
                  （间隔出现过{sortListObj[currentJiange]}次）
                </td>
                <td>
                  <IndexLocation locationIndex={locationIndex}></IndexLocation>
                </td>
              </tr>
            })
          }
        </tbody>
      </table>
      <Form
        name="basic"
        labelCol={{
          span: 8,
        }}
        wrapperCol={{
          span: 16,
        }}
        style={{
          maxWidth: 600,
        }}
        initialValues={{
          remember: true,
        }}
        autoComplete="off"
        onFinish={(values)=>{
          let filterResult = getFilterResult({
            allRedBallList: allRedBallList,
            allRedBallStrList: allRedBallStrList,
            historyList: historyList,
            historyResultStrList: historyResultStrList,
            historyOddEvenList: historyOddEvenList
          });
          
          let num = [values.startNum.split(" ")];
          setData(filterResult);
          setBuyResult(num);
        }}
      >
        <Form.Item
          label="开奖号码"
          name="startNum"
        >
          <Input />
        </Form.Item>

        {
          buyResult.map((item, index)=>{
            
            let result = false;
            data.filterResult.find((redBollItem:[])=>{
              if(item.join("") === redBollItem.join("")){
                result = true;
                return true;
              }
            })
            let text = "遗憾，不在过滤结果内"
            if(result){
              text = "恭喜，在过滤结果内"
            }

            return <p key={index}>{item.join(" ")}：{text}</p>
            
          })
        }

        <Form.Item
          wrapperCol={{
            offset: 8,
            span: 16,
          }}
        >
          <Button type="primary" htmlType="submit">
            验证
          </Button>
        </Form.Item>
          
      </Form>
    </PageContainer>
  );
};

export default Table;